#coding=utf-8 


"""
mingw的下载地址：http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/
pycrypto的下载地址：http://www.dlitz.net/software/pycrypto/
paramiko的下载地址：http://pypi.python.org/pypi/paramiko

先安装mingw  安装程序    Mingw,安装选  C编译器就可以。记得把MSYS也勾上

安装扩展 pycrypto
安装扩展 paramiko


cd  paramiko 目录
cd /d  f:\temp\pycrypto
输入D:\Python26\python setup.py install    安装有问题
cd pycrypto 目录 
输入D:\Python26\python setup.py install 

D:\Python26\python.exe -c "import setuptools;
-----------
?
error: Unable to find vcvarsall.bat
!1
在python的lib\distutils目录下，找到distutils.cfg文件（如果没有，就创建一个）。加上下面内容：
[build] 
compiler=mingw32
!2
setup.py build -c mingw32


--下载 mingw完整离线版 minGW_all.rar
set path=%path%;D:\MinGW\bin;D:\MinGW\msys\1.0\bin

setup.py build -c mingw32
setup.py install   



?
RuntimeError("autoconf error")
!
依赖软件没有装全







"""
import paramiko , sys
reload(sys)  
sys.setdefaultencoding('gbk')
 

def hp():
    """ 帮助函数"""
    help(  paramiko.SSHClient ) 
    sys.exit()
hp()    
    
    


client = paramiko.SSHClient() 
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 



"""打开ssh"""
 
try:
    #raise NameError, u'这里有错误'
    
    #raise Exception('spam', 'eggs')
    
    #raise RuntimeError("Something bad happened")  
    
    client.connect('192.168.0.231', 22, username='root', password='oracle', timeout=2) 
except Exception , e:  
    print  '1-----' ,sys.exc_info()
    print '2-----' ,e  
    print '4-----' ,e.args 



#except IOError as err:  
#    print("I/O error: {0}".format(err))  
#except ValueError:  
#    print("Could not convert data to an integer.")  
#except:  
#    print("Unexpected error:", sys.exc_info()[0])  

    print '-----exit()-------' 
    sys.exit()




stdin, stdout, stderr = client.exec_command('df ') 
"""读取标准输出"""


for std in stdout.readlines(): 
    print std, 
    

stdin, stdout, stderr = client.exec_command('df -lh ') 
"""读取标准输出"""


for std in stdout.readlines(): 
    print std, 


 
client.close() 



